package com.heima.controller;

import com.heima.pojo.dto.ClassifyPagingDto;
import com.heima.pojo.vo.Classify2VO;
import com.heima.pojo.vo.PagingVO;
import com.heima.service.ClassifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/skuClass")
@Slf4j
public class ClassifyController {
    @Autowired
    private ClassifyService classifyService;

    //分类搜索
    @GetMapping("/search")
    public PagingVO getClassify(ClassifyPagingDto dto) {
        log.info("分类搜索{}", dto);
        return classifyService.getClassify(dto);

    }

    //新增
    @PostMapping
    public Boolean addClassify(@RequestBody ClassifyPagingDto dto) {
        log.info("新增分类----------------------{}", dto);
        return classifyService.addClassixfy(dto);
    }

    /**
     *  获取分类基本信息
     */
    @PutMapping("/skuClass/{classId}")
    public Classify2VO selectIdClassify(@PathVariable String classId) {
        log.info(" 获取分类基本信息----------------------{}", classId);
        Classify2VO classifyVo =   classifyService.selectIdClassify(classId);
        log.info("获取分类基本信息返回-------------------{}", classifyVo);
        return classifyVo ;
    }
    //修改分类
    @PutMapping("/{classId}")
    public Boolean updateClassify(@PathVariable String classId ,  @RequestBody String className) {
        log.info("修改分类----------------------{}{}", classId, className);
        return classifyService.updateClassify(classId,className);
    }
    //删除分类
    @DeleteMapping("/{classId}")
    public Boolean deleteClassify(@PathVariable String classId) {
        log.info("删除分类----------------------{}", classId);
        return classifyService.deleteClassify(classId);
    }

}
